  export default {
    data() {
      return {
        remainingTime: 0,
        timeString: '00:00:00',
        interval: null
      }
    },
    methods: {
      padZero(num) {
        return num < 10 ? '0' + num : num.toString()
      },
      calculateTime() {
      
        const hours = this.padZero(Math.floor((this.remainingTime / (1000 * 60 * 60)) % 24))
        const minutes = this.padZero(Math.floor((this.remainingTime / (1000 * 60)) % 60))
        const seconds = this.padZero(Math.floor((this.remainingTime / 1000) % 60))
        this.timeString = `${hours}:${minutes}:${seconds}`
      },
      startCountDown(timestamp=0) {
        this.remainingTime = timestamp
        
        if (this.interval) {
          clearInterval(this.interval)
        }
        
        this.interval = setInterval(() => {
          this.remainingTime -= 1000
          if (this.remainingTime <= 0) {
            clearInterval(this.interval)
            return;
          }
          this.calculateTime()
          
         
        }, 1000)
      }
    },
    onUnload() {
      if (this.interval) {
        clearInterval(this.interval)
      }
    },
  }